package cn.lxh.system.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 配置类: 登录拦截配置拦截哪些请求, 哪些请求不走拦截器
 */
@Configuration
public class LoginInterceptorConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册拦截器
        registry.addInterceptor(loginInterceptor)
                // 拦截所有请求
                .addPathPatterns("/**")
                // 放行登录的请求, 放行跟注册相关的, 放行跟测试相关的
                .excludePathPatterns("/login/**")
                // 放行swagger
                .excludePathPatterns("/swagger-resources/**", "/webjars/**",
                        "/v2/**", "/swagger-ui.html/**")
                // minio不是axios请求, 不会携带token, 登录拦截器中就直接响应toLogin, 也不会经过axios后置拦截器, 所以要排除
                .excludePathPatterns("/minio");
    }
}